package cn.dm.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("test")
public class TestController {

    /**
     * 访问 http://localhost:8080/test/hello
     * 网页出现 hello
     */
    @GetMapping("hello")
    public String hello() {
        return "hello";
    }

    /**
     * 访问
     * (1) http://localhost:8080/test/zhangsan/20
     * 页面:my name is zhangsan and my age is 20
     * (2) http://localhost:8080/test/jack/22
     * my name is jack and my age is 22
     */
    @GetMapping("{name}/{age}")
    public String show(@PathVariable("name") String name, @PathVariable("age") Integer age) {
        return "my name is " + name + " and my age is " + age;
    }
}
